package com.shoujifeng.snowmusic.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper{
	//private SQLiteDatabase database;
	public DatabaseHelper(Context context , String name ,CursorFactory factory , int version) {
		super(context, "musicplay.db", null,1);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		Cursor cursor = null;
        try {
                cursor = db.rawQuery("SELECT * FROM sqlite_master WHERE type = ? AND name = ?", new String[]{"table","info"});
                if(cursor.moveToNext()){
                	Log.d("DatabaseHelper","该表已经存在");
                }else{
                	db.execSQL("CREATE TABLE info (path VARCHAR(1024), threadid INTEGER , " +
            				"downloadlength INTEGER , PRIMARY KEY(path,threadid))");
                	db.execSQL("Create Table SongMenu (id integer primary key autoincrement,name text,musicName text,playerName text,duration INTEGER,size INTEGER,url text)");
                	db.execSQL("Create Table MusicList (id integer primary key autoincrement,musicName text,album text,playerName text,duration INTEGER,size INTEGER,url text)");
                	db.execSQL("Create Table Conllect (id integer primary key autoincrement, idx integer, uid integer)");
                	db.execSQL("Create Table Download (id integer primary key autoincrement, uid integer, name text, singer text, icon_url text, file_url text, url text, lenght text, clenght text, over integer)");
                	
                }
                cursor.close();
        } catch (Exception e) {
        	e.printStackTrace();
        }
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}
}
